import java.util.*;

public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> linkedList2 = new LinkedList<Integer>();
        linkedList2.add(1);//默认都是尾插
        linkedList2.addLast(3);
        linkedList2.addLast(4);
        linkedList2.addLast(5);
        System.out.println(linkedList2);

        System.out.println("===== ListIterator ====");
        ListIterator<Integer> lit2 = linkedList2.listIterator(linkedList2.size());
        while (lit2.hasPrevious()) {
            System.out.print(lit2.previous() + " ");
        }
        System.out.println();

        System.out.println("===== ListIterator ====");
        ListIterator<Integer> lit = linkedList2.listIterator();
        while (lit.hasNext()) {
            System.out.print(lit.next() + " ");
        }
        System.out.println();

        System.out.println("===== Iterator ====");
        Iterator<Integer> it = linkedList2.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();


        System.out.println("=====for each====");

        for (Integer x : linkedList2) {
            System.out.print(x + " ");
        }
        System.out.println();

        System.out.println("=====for====");
        for (int i = 0; i < linkedList2.size(); i++) {
            System.out.print(linkedList2.get(i) + " ");
        }
        System.out.println();


    }

    public static void main6(String[] args) {
        List<Integer> linkedList1 = new LinkedList<>();
        LinkedList<Integer> linkedList2 = new LinkedList<>();
        linkedList2.add(1);//默认都是尾插
        linkedList2.addFirst(2);
        linkedList2.addLast(3);
        linkedList2.addLast(4);
        linkedList2.addLast(5);
        System.out.println(linkedList2);

        ArrayList<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(21);
        list.add(31);

        linkedList2.addAll(list);

        System.out.println(linkedList2);

        linkedList2.remove(2);
        System.out.println(linkedList2);

    }


//    public static void main7(String[] args) {
//        MyLinkedList myLinkedList = new MyLinkedList();
//        myLinkedList.addLast(1);
//        myLinkedList.addLast(2);
//        myLinkedList.addLast(3);
//        myLinkedList.addLast(4);
//        myLinkedList.addLast(5);
//        myLinkedList.addLast(1);
//        myLinkedList.addLast(1);
//        myLinkedList.addLast(1);
//        myLinkedList.addLast(1);
//
//        myLinkedList.display();
//
//
//        myLinkedList.addIndex(3, 9);
//        myLinkedList.clear();
//        //myLinkedList.addIndex(3,9);
//        //myLinkedList.display();
//
//    }
}